package com.atguigu.gmall.activity.controller;

import com.atguigu.gmall.activity.service.SecKillService;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.activity.SeckillGoods;
import com.atguigu.gmall.model.activity.SeckillOrder;
import com.baomidou.mybatisplus.annotation.TableId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 秒杀controller
 */
@RestController
@RequestMapping(value = "/seckill/goods")
public class SecKillController {

    @Autowired
    private SecKillService secKillService;
    /**
     * 获取秒杀商品列表
     * @param date
     * @return
     */
    @GetMapping(value = "/list/{time}")
    public Result<List<SeckillGoods>> getGoodsList(@PathVariable("time") String date){
        List<SeckillGoods> goodsList = secKillService.getGoodsList(date);
        return Result.ok(goodsList);
    }

    /**
     * 获取秒杀商品详情
     * @param date
     * @param id
     * @return
     */
    @GetMapping(value = "/one/{time}/{id}")
    public Result<SeckillGoods> getGoods(@PathVariable("time") String date,
                                         @PathVariable("id") String id){
        SeckillGoods goods = secKillService.getGoods(date, id);
        return Result.ok(goods);
    }
}
